<?php
namespace app\http\controller;
use think\Controller;
use app\service\hzcityService;
use app\service\apiparkService;
use app\service\orderService;
use app\service\swooleService;
use think\facade\Log;
use think\Db;
class Test extends Controller{

    public function test(){
        
        $dir='/www/wwwroot/parkingcommunity/runtime/serverlog';
        $result=$this->xf_scandir($dir);
        echo "<pre>";
        var_dump($result);
    }


    public function scandir($dir){
        $result=array();
        $handle=opendir($dir);
        if($handle){
            while(($file=readdir($handle))!==false){
                if(is_dir($dir."/".$file)){
                    $result[$file]=$this->scandir($dir."/".$file);
                }else{
                    $result[]=$dir."/".$file;
                }
            }
            closedir($dir);
            return $result;
        }
    }











    public function readdir1($dir){
        $result=array();
        $handle=opendir($dir);
        if($handle){
            while(($file=readdir($handle))!==false){
                if($file!="."&&$file!=".."){
                    $cur_path =$dir."/".$file;
                    if(is_dir($cur_path)){
                        $result['dir'][$cur_path] = $this->readdir1 ( $cur_path );
                    }else{
                        $result[]=$cur_path;
                    }
                }
            }
            closedir($handle);
            return $result;
        }

    }
    public function xf_scandir($dir)
    {
        $files = array();
        if( $handle=opendir($dir) ){                             //$handle=Resource id #3

            while( ($file = readdir($handle)) !== false ){
                if( $file != ".." && $file != "." ){
                    if( is_dir($dir . "/" . $file) ){   //文件夹c
                        $files[$file] = $this->xf_scandir($dir . "/" . $file);
                    }else{
                        $files[] = $file;
                    }
                }
            }


            closedir($handle);
            return $files;
        }
    }




}